package com.itzou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itzou.domain.ScheduledTask;
import com.itzou.mapper.ScheduledTaskMapper;
import com.itzou.service.ScheduledTaskService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ScheduledTaskServiceImpl implements ScheduledTaskService {

    private final ScheduledTaskMapper scheduledTaskMapper;

    @Override
    public ScheduledTask findById(Integer id) {
        return scheduledTaskMapper.selectById(id);
    }

    @Override
    public Page<ScheduledTask> findByPage(Integer pageNo, Integer pageSize) {
        return scheduledTaskMapper.selectPage(new Page<>(pageNo, pageSize), null);
    }

    @Override
    public void deleteByCondition(ScheduledTask scheduledTask) {
        // 根据条件删除定时任务
        QueryWrapper<ScheduledTask> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("service_name", scheduledTask.getServiceName());
        queryWrapper.eq("service_method", scheduledTask.getServiceMethod());
        scheduledTaskMapper.delete(queryWrapper);
    }

    @Override
    public void insert(ScheduledTask scheduledTask) {
        scheduledTaskMapper.insert(scheduledTask);
    }

    @Override
    public void updateStatus0(String serviceName, String serviceMethod) {
        scheduledTaskMapper.updateStatus0(serviceName, serviceMethod);
    }

    @Override
    public void updateStatus1(String serviceName, String serviceMethod) {
        scheduledTaskMapper.updateStatus1(serviceName, serviceMethod);
    }

    @Override
    public ScheduledTask selectByCondition(String serviceName, String serviceMethod) {
        return scheduledTaskMapper.selectByServiceNameAndServiceMethod(serviceName, serviceMethod);
    }

}
